
const TechProductDetail = {
    getDetail: function () {
        let _this = this;
        let id = common.getQueryString("id")
        ajax_get(host + `/ajax/productsDetail/${id}`,
            true,
            {},
            (res) => {
                res = JSON.parse(res)
                console.log(res)
                if (res.detail) {
                    const { detail, correlation } = res;
                    $(".currentName").html(` <a href="product-detail.html?id=${detail.id}">${detail.title}</a>`)
                    $(".pro-title-wrap").text(detail.title)
                    $(".pro-lable-wrap span:nth-child(1)").text("产品型号：" + detail.model)
                    $(".pro-lable-wrap span:nth-child(2)").text("类别：" + detail.cate_id)
                    $(".pro-text-wrap").text(detail.descript)
                    let arrEntities = {
                        'lt': '<',
                        'gt': '>',
                        'nbsp': ' ',
                        'amp': '&',
                        'quot': '"'
                    };
                    detail.content = detail.content.replace(/&(lt|gt|nbsp|amp|quot);/ig, function (all, t) {
                        return arrEntities[t]
                    })
                    $(".pro-read-bjq").html(detail.content)
                    _this.renderMaxImg(detail.image_s)
                    _this.renderRelated(correlation)
                    common.ClickMaxImg()
                }
            },
            err => {
                console.log(err)
            }
        );
    },
    renderMaxImg: function (data) {
        let str = '', str2 = ''
        if (data && data.length > 0) {
            data.forEach((item, index) => {
                str += `<div class="pro-img-li">`
                if (index == 0) {
                    str += `<div class="swiper-max-img pro-left-img cover data3 data-seo3">`
                } else {
                    str += ` <div class="swiper-max-img pro-right-img cover data3 data-seo3">`
                }
                str += `<img src="${item}" alt="">
                </div>
            </div>`
            })
            data.forEach(item => {
                str2 += `<div class="swiper-slide">
                <div class="pro-black-img data3 data-seo3">
                    <img src="${item}" alt="">
                </div>
            </div>`
            })
        }
        $(".pro-img-min").html(str)
        $(".detail-img-container").html(str2)
    },
    renderRelated: function (data) {
        let str = ""
        if (data && data.length > 0) {
            data.forEach(item => {
                str += `<div class="pro-list-li wow fadeInUp">
                <div class="imgJsWrap">
                    <div class="pro-list-img">
                        <a class="img-black cover data3 data-seo3" href="product-detail.html?id=${item.id}">
                            <img src="${item.image}" alt="">
                        </a>
                    </div>
                    <div class="pro-list-read">
                        <div class="pro-list-span space-over" title="${item.title}">
                            <a href="product-detail.html?id=${item.id}">${item.title}</a>
                        </div>
                        <div class="pro-list-span space-list-over">
                            ${item.descript}</div>
                    </div>
                    <div class="pro-border"></div>
                </div>
            </div>`
            });
        }
        $(".pro-list-ul").html(str)
    }
}


$(function () {
    TechProductDetail.getDetail()
    common.init()
    common.getPhoneInfo()
    common.getBanner("products")
    common.getFootProductCatList()
    common.getFootInfo()
})